package com.venueproject.controlle;


import com.venueproject.pojo.Appoiment;
import com.venueproject.pojo.PageBean;
import com.venueproject.pojo.Result;
import com.venueproject.service.AppoimentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//请求处理类
@RestController
@CrossOrigin(origins="*")
@Slf4j
public class AppoimentControll {
    @Autowired
    private AppoimentService appoimentService;

    @GetMapping("/venue/appoiment")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer pageSize,
                       String number, String name){
        log.info("分页查询, 参数: {},{}",page,pageSize);
        //调用service分页查询
        PageBean pageBean = appoimentService.page(page,pageSize,number,name);
        return Result.success(pageBean);
    }

    @GetMapping("/venue/record")
    public Result getAppoiment(){
        log.info("查询预约信息");
        return Result.success(appoimentService.getAppoiment());
    }

    @GetMapping("/venue/select")
    public Result selectAppoiment(@RequestParam String number){
        log.info("判断场地编号{}当日是否预约",number);
        return Result.success(appoimentService.selectAppoiment(number));
    }

    @PostMapping("/venue/insert")
    public Result addAppoiment(@RequestBody Appoiment appoiment){
        log.info("插入预约信息{}",appoiment);
        appoimentService.insertAppoiment(appoiment);
        return Result.success();
    }

    @GetMapping("/venue/Addappoiment")
    public void Addappoiment(@RequestParam("id") int id){
        log.info("预约人数加1");
        appoimentService.Addappoiment(id);
    }


}
